<template>
  <div class="table-page-search-wrapper">
    <el-form :model="searchForm" ref="searchForm" label-width="100px" class="demo-ruleForm">
      <el-row :gutter="10">
        <el-col :md="6" :sm="12" :xs="24">
          <el-form-item label="商品名称:">
            <a-input v-model="searchForm.goodsName" placeholder="请输入商品名称" />
          </el-form-item>
        </el-col>
        <el-col :md="6" :sm="12" :xs="24">
          <el-form-item label="商品条码:">
            <a-input v-model="searchForm.barCode" placeholder="请输入条码或后四位" />
          </el-form-item>
        </el-col>
        <el-col :md="8" :sm="12" :xs="24">
          <el-form-item label="商品类目:">
            <a-cascader
              :options="categoryIdList"
              v-model="pids"
              change-on-select
              placeholder="请选择商品类目"
            ></a-cascader>
          </el-form-item>
        </el-col>
        <el-col :md="6" :sm="12" :xs="24">
          <el-form-item label="制单时间:">
            <a-range-picker
              @change="cxsjChange"
              style="width:100%"
              v-model="time"
              
              show-time
              format="YYYY-MM-DD HH:mm:ss"
            >
              <a-icon slot="suffixIcon" type="smile" />
            </a-range-picker>
          </el-form-item>
        </el-col>
        <el-col :md="6" :sm="12" :xs="24">
          <el-form-item label="采购单号:">
            <a-input v-model="searchForm.purchaseInfoId" placeholder="请输入采购单号" />
          </el-form-item>
        </el-col>
        <!-- <el-col :md="6" :sm="12" :xs="24">
          <el-form-item label="供应商:">
            <a-select
              v-model="searchForm.supplierMerchantId"
              placeholder="请选择供应商"
              style="width:100%"
            >
              <a-select-option
                v-for="item in supplierMerchantIdList"
                :key="item.value"
                :value="item.value"
              >{{item.label}}</a-select-option>
            </a-select>
          </el-form-item>
        </el-col>-->
        <el-col :md="6" :sm="12" :xs="24">
          <el-form-item label="单据状态:">
            <a-select v-model="searchForm.status" placeholder="请选择单据状态" style="width:100%">
              <a-select-option
                v-for="item in djztList"
                :key="item.value"
                :value="item.value"
              >{{item.label}}</a-select-option>
            </a-select>
          </el-form-item>
        </el-col>
        <el-col :md="6" :sm="12" :xs="24">
          <div style="margin-left:30px">
            <a-button type="primary" icon="search" @click="searchAction()">查询</a-button>
            <a-button icon="delete" @click="resetSearch()" style="margin-left: 8px;">重置</a-button>
          </div>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>
import { merchantinfosupply, platformgoodscategory } from '@/api/shop/procurement.js'
import moment from 'moment'
export default {
  name: 'search',
  data() {
    return {
      supplierMerchantIdList: [], //zhaungt
      categoryIdList: [],
      searchForm: {},
      djztList: [
        {
          label: '待配送',
          value: '00',
        },
        {
          label: '配送中',
          value: '01',
        },
        {
          label: '已完成',
          value: '02',
        },
        {
          label: '已取消',
          value: '03',
        },
      ],
      time: [],
      pids: [],
    }
  },
  mounted() {
    this.getDic()
  },
  methods: {
    moment,
    searchAction() {
      //执行搜索
      if (this.pids) {
        if (this.pids.length > 1) {
          //商品类目
          this.searchForm.categoryId = this.pids[1]
          this.searchForm.pid = this.pids[0]
        } else {
          this.searchForm.categoryId = this.pids[0]
          this.searchForm.pid = this.pids[0]
        }
      }
      this.$emit('search')
    },
    resetSearch() {
      this.searchForm = {}
      this.time = []
      this.pids = []
      this.$emit('resetSearch')
    },
    getSearchForm() {
      //获取高级搜索条件
      return {
        ...this.searchForm,
      }
    },
    cxsjChange(e) {
      console.log('cxsjChange', e)
      if(e.length == 0) return false
      this.searchForm.beginTime = this.formDate(e[0]._d)
      this.searchForm.endTime = this.formDate(e[1]._d)
      console.log('cxsjChange', this.searchForm)
    },
    getDic() {
      merchantinfosupply().then((val) => {
        //供应商
        let data = val.data
        this.supplierMerchantIdList = data.records.map((item) => {
          return {
            value: item.merchantId,
            label: item.companyName,
          }
        })
      })
      platformgoodscategory({ businessType: '' }).then((val) => {
        //商品类目
        let data = val.data
        console.log(data)
        this.categoryIdList = data.map((item) => {
          return {
            value: item.categoryId,
            label: item.categoryName,
            children: item.children.map((items) => {
              return {
                value: items.categoryId,
                label: items.categoryName,
              }
            }),
          }
        })
      })
    },
  },
}
</script>


<style lang="less">
</style>>
